package com.witmore.neutron.ai.web.controller.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.witmore.neutron.ai.db.entity.AgentDeploymentDO;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 智能体部署响应对象
 * @author 豆子高
 * @date 2025-09-17
 */
@Data
public class AgentDeploymentResponse {

    private Integer id;

    /**
     * 智能助手id
     */
    private Integer agentId;

    /**
     * 智能助手编码
     */
    private String agentCode;

    /**
     * 用户id
     */
    private Integer userId;

    /**
     * 服务商ID
     */
    private Integer providerId;

    /**
     * 智能助手图标
     */
    private String agentIcon;

    /**
     * 智能助手名称
     */
    private String agentName;

    /**
     * 智能助手名称简写
     */
    private String agentNameAbbr;

    /**
     * 智能助手描述
     */
    private String agentDesc;

    /**
     * 智能助手类型id
     */
    private Byte agentSceneTypeId;

    /**
     * 部署状态1已部署 2停用
     */
    private Byte deployStatus;

    /**
     * 部署状态描述
     */
    private String deployStatusDesc;

    /**
     * 总聊天次数
     */
    private Integer totalChatCount;

    /**
     * 其他配置json格式
     */
    private String configJson;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;


    public static AgentDeploymentResponse fromEntity(AgentDeploymentDO entity) {
        if (entity == null) {
            return null;
        }

        AgentDeploymentResponse response = new AgentDeploymentResponse();
        response.setId(entity.getId());
        response.setAgentId(entity.getAgentId());
        response.setAgentCode(entity.getAgentCode());
        response.setUserId(entity.getUserId());
        response.setProviderId(entity.getProviderId());
        response.setAgentIcon(entity.getAgentIcon());
        response.setAgentName(entity.getAgentName());
        response.setAgentNameAbbr(entity.getAgentNameAbbr());
        response.setAgentDesc(entity.getAgentDesc());
        response.setAgentSceneTypeId(entity.getAgentSceneTypeId());
        response.setDeployStatus(entity.getDeployStatus());
        response.setDeployStatusDesc(getDeployStatusDesc(entity.getDeployStatus()));
        response.setTotalChatCount(entity.getTotalChatCount());
        response.setConfigJson(entity.getConfigJson());
        response.setUpdateTime(entity.getUpdateTime());
        response.setCreateTime(entity.getCreateTime());

        return response;
    }

    private static String getDeployStatusDesc(Byte deployStatus) {
        if (deployStatus == null) {
            return "未知";
        }
        return switch (deployStatus) {
            case 1 -> "已部署";
            case 2 -> "已停用";
            default -> "未知";
        };
    }
}
